﻿/**
* 作者: 常亮
* 日期: 2009-11-18
* 功能: 用于Javascript的包含文件
*/
var SBasePath = "/Web/AdminManage";
var WebBasePath = "/Web";

//var SBasePath = "/AdminManage";
//var WebBasePath = "";

function includeJs(_sl) {
	if (!_sl) return;
	var ss = document.getElementsByTagName('script');
	for (var i=0; i<_sl.length; i++) {
		var _sf = _sl[i];
		var _f = false;
		for (var j=0; j<ss.length; j++) {
			var _s = ss[j].getAttribute('src');
			if (_s && _s==_sf) {
				_f = true;
				break;
			}
		}
		if (!_f) {
			document.write('<scr'+'ipt type="text/javascript" src="'+ _sf +'"></scr'+'ipt>');
		}
	}
}

//包含Css文件
function includeCss(_sl) {
	if (!_sl) return;
	var ss = document.getElementsByTagName('link');
	for (var i=0; i<_sl.length; i++) {
		var _sf = _sl[i];
		var _f = false;
		for (var j=0; j<ss.length; j++) {
			var _s = ss[j].getAttribute('rel');
			if (_s && _s==_sf) {
				_f = true;
				break;
			}
		}
		if (!_f) {
		document.write('<link type="text/css" rel="stylesheet" href="'+_sf+'" /> ');		
		}
	}
}

var GetXmlData=function(xmlObj,tagName)
{
    var node = xmlObj.getElementsByTagName(tagName);
    
    if(node!=null && node[0]!=null&& node[0].firstChild!=null)
    {
        return node[0].firstChild.data;
    }
    return "";
}

//获取分页参数，或者其它用户参数
var MapPage=function(xmlDoc,tagName)
{  
    var root = xmlDoc.responseXML.documentElement;
    
    if(root!=null)
    {
        var PageObj = root.getElementsByTagName("Page");
         
         if(PageObj!=null && PageObj[0]!=null)
         {      
            return GetXmlData(PageObj[0],tagName);
         }
     }
     return "";
};



//兼容浏览器
function jb()
{ 
   var A=null; 
   try
   { 
     A=new ActiveXObject("Msxml2.XMLHTTP");
   } 
   catch(e)
   { 
       try
       { 
          A=new ActiveXObject("Microsoft.XMLHTTP");
       } 
       catch(oc)
       { 
          A=null;
       } 
    } 

    if ( !A && typeof XMLHttpRequest != "undefined" )
    { 
       A=new XMLHttpRequest();
    } 
    return A;
}


function request(paramName) {
    //获取URL的字符串
    var sSource = String(window.document.location);
    var sName = paramName;
    var sReturn = "";
    var sQUS = "?";
    var sAMP = "&";
    var sEQ = "=";
    var iPos;
    //获取sSource中的"?"，无则返回 -1
    iPos = sSource.indexOf(sQUS);
    if (iPos == -1) return;
    //汲取参数，从iPos位置到sSource.length-iPos的位置，
    //若iPos = -1，则：从-1 到 sSource.length+1
    var strQuery = sSource.substr(iPos, sSource.length - iPos);
    // alert(strQuery); 
    //先全部转换为小写
    var strLCQuery = strQuery.toLowerCase();
    var strLCName = sName.toLowerCase();
    //从子字符串strLCQuery中查找“?”、参数名，以及“=”，即“?参数名=”
    iPos = strLCQuery.indexOf(sQUS + strLCName + sEQ);
    //alert(iPos);
    //如果不存在
    if (iPos == -1) {   //继续查找可能的后一个参数，即带“&参数名=”
        iPos = strLCQuery.indexOf(sAMP + strLCName + sEQ);
    }
    //判断是否存在参数
    if (iPos != -1) {
        sReturn = strQuery.substr(iPos + sName.length + 2, strQuery.length - (iPos + sName.length + 2));
        var iPosAMP = sReturn.indexOf(sAMP);
        if (iPosAMP == -1) {
            return sReturn;
        } else {
            sReturn = sReturn.substr(0, iPosAMP);
        }
    }
    return sReturn;
}

//样式读取Cookie

var aCookie = document.cookie.split(";");
for (var i = 0; i < aCookie.length; i++) {
    var aCrumb = aCookie[i].split("=");
    var str = aCrumb[0];
    str = str.replace(" ", "");
    if (str == "style") {
        style = unescape(aCrumb[1]);
    }
}








///判断URL地址的正则表达式为:http(s)?://([\w-]+\.)+[\w-]+(/[\w- ./?%&=]*)?

function checkeURL(URL) {
    var str = URL;
    //在JavaScript中，正则表达式只能使用"/"开头和结束，不能使用双引号
    //判断URL地址的正则表达式为:http(s)?://([\w-]+\.)+[\w-]+(/[\w- ./?%&=]*)?
    //下面的代码中应用了转义字符"\"输出一个字符"/"
    var Expression = /http(s)?:\/\/([\w-]+\.)+[\w-]+(\/[\w- .\/?%&=]*)?/;
    var objExp = new RegExp(Expression);
    if (objExp.test(str) == true) {
        return true;
    } else {
        return false;
    }
} 








